package test.web;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import hyl.core.Amy;
import hyl.core.MyCharset;
import hyl.core.MyDate;
import hyl.core.conf.MyConst;
import hyl.core.io.MyFile;
import hyl.core.io.ZipUpload;
public class testupload {
	public static void main(String[] arrg) {
		testupload dh = new testupload();
		dh.test5();
		// dh.test6();
		// dh.test4();
		// dh.test1();
		// dh.test2();
		// dh.test3();
	}
	public void test5() {
		String 临时路径 = MyConst.getInstance().get("CLI_TEMP_PATH");
		String 上传路径 = MyConst.getInstance().get("CLI_UPLOAD_URL");
		String 系统名称 = MyConst.getInstance().get("SYS_NAME");
		String 全量包名 = "a001" + MyDate.getNow("yyyyMMdd");
		String 增量包名 = "p001" + MyDate.getNow("yyyyMMdd");
		ZipUpload upload = new ZipUpload(临时路径, 上传路径);
		JSONObject sp=new JSONObject();	
		sp.put("goods_id", "1");
		sp.put("goods_name", "xx");
		sp.put("state", "1");
		sp.put("qr_code_one", "98199999");
		sp.put("price", "23.4");
		sp.put("oprice", "24.9");
		sp.put("pic_url", "http://35u5.uu/3555.jpg");
		sp.put("goods_msg", "规格");		
		sp.put("amount", "124");
		JSONObject sp2=new JSONObject();
		sp2.put("goods_id", "2");
		sp2.put("goods_name", "yy");
		sp2.put("state", "0");
		sp2.put("qr_code_one", "21344");
		sp2.put("price", "13.4");
		sp2.put("oprice", "14.9");
		sp2.put("pic_url", "http://35u5.uu/355888.jpg");
		sp2.put("amount", "100");
		long start = System.currentTimeMillis();
		try {
			JSONArray li=new JSONArray();
			li.add(sp);
			li.add(sp2);
			// 全量数据
			upload.inputFile(全量包名, "商品数据.json", li.toJSONString());
			//String json = "[{广告:lkcjvzj}]";
			//upload.inputFile(全量包名, "广告数据.json", json);
			
			
			// 增量数据
			JSONArray li2=new JSONArray();
			li2.add(sp2);
			upload.inputFile(增量包名, "商品数据.json", li2.toJSONString());
			//json = "[]";
			//upload.inputFile(增量包名, "广告数据.json", json);
			// 开始压缩并上传
			
			// 营业厅
			Map<String, String> data = new HashMap<>();		
			data.put("s", 系统名称);//系统名称
			data.put("g1", "zip");//文件类型
			data.put("g2", "g001");//组织机构
			String result = upload.zipSubmit(data);
			
			System.out.println(result);
			JSONObject jo = JSON.parseObject(result);
			Integer code = jo.getInteger("CODE");
			JSONArray msgs = jo.getJSONArray("MSG");
			JSONObject info = new JSONObject();
				for (int i = 0; i < msgs.size(); i++) {
				JSONObject msg = msgs.getJSONObject(i);
				String name = msg.getString("oldname");
				String url = msg.getString("path");
				String md = msg.getString("md5");
				int ver = 11;
				JSONObject nso_info = new JSONObject();
				nso_info.put("url", url);
				nso_info.put("version", ver);
				nso_info.put("md5_code", md);
				if (name.startsWith("p")) {
					info.put("partPackage", nso_info);
				} else {
					info.put("allPackage", nso_info);
				}
			}
			// 合并数据
			JSONObject nso = new JSONObject();
			nso.put("code", code);
			nso.put("msg", "获取成功");
			nso.put("info", info);
			System.out.println(nso.toJSONString());/**/
			long end = System.currentTimeMillis();
			System.out.println("传输完成，耗时：" + (end - start) + " ms");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void test6() {
		File f = MyFile.openFile("d:\\t1.zip");
		try {
			MyFile.doZipDir("F:\\领航\\项目", new FileOutputStream(f));
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
